<?php echo $this->render('link/header.phtml') ?>
<?php $gridId=uniqid(); ?>
//常用变量初始化

var module="progress";
var gridTitle="链接检测执行";
var progressServerUrl=baseUrl+"/link/progress";
    
                 


var pbar2 = new Ext.ProgressBar({
  		fieldLabel:'进度',
        text:'Ready',
        id:'pbar2',
        cls:'left-align'
    });

    
var progress=new Ext.FormPanel({
	frame:true,
    title:gridTitle,
    labelWidth:100,
    labelAlign:'top',
    autoWidht:true,
    autoHeight:true,
    renderTo:'grid_<?=$gridId?>',
    bodyStyle:'padding:20px 10px 10px 10px;',    
    items:[{xtype:'label',
    		text:"共有"+<?=$this->linkcount?>+"条数据待检测"        
},pbar2],
    buttons:[
    {
    id:'begin',
    text:'开始执行',
    handler:function(){
    	 	Runner.run(pbar2, Ext.get('begin'), <?=$this->linkcount?>, function(){
            pbar2.reset();
            pbar2.updateText('执行完成.');
        });
    	}
    },{
    id:'cancel',
    text:'退出',
    handler:function(){
    	Ext.getCmp('content').remove(Ext.getCmp('content').getActiveTab());
    	}
    }
    ]    
    });
    
var Runner = function(){
	var v=0;
    var f = function(pbar, btn, count, cb){    	
        return function(){
            if(v >= count){            	
                	btn.dom.disabled = false;
                	cb();     
            }else{
             Ext.Ajax.request({
             url:progressServerUrl,
             method:'POST',
             params:{id:v},
             failure:function(form,action){
             	//console.log("失败"+v);
             },
             success:function(form,action){             	
             	pbar.updateProgress(v/count, '正在检测第<font color="#FF0000" font-weight="bold">' + v + '</font> of '+count+'条数据...');
             }
             });                        
            }
            v++;
       };
    };
    return {
        run : function(pbar, btn, count, cb){                             	
            var interval=setInterval(f(pbar, btn, count, cb), <?=$this->interval?>);            
        }
    }
}();


});
</script>
<body style="width:98%;height:100%">
<div id='grid_<?=$gridId?>'></div>
</html>
